package com.lvs.zmwz.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lvs.zmwz.auth.StpUserUtil;
import com.lvs.zmwz.entity.OrderList;
import com.lvs.zmwz.entity.Shop;
import com.lvs.zmwz.entity.SysManager;
import com.lvs.zmwz.service.IOrderListService;
import com.lvs.zmwz.service.IShopService;
import com.lvs.zmwz.service.ISysManagerService;
import com.lvs.zmwz.util.IdentityUtil;
import com.lvs.zmwz.util.QPage;
import com.lvs.zmwz.util.ResultView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/api/front/order-list")
public class AppOrderListController {

    @Autowired
    private IOrderListService iOrderListService;


    @Autowired
    private IShopService iShopService;

    @Autowired
    private ISysManagerService iSysManagerService;

    /**
     * 用户下单
     * @return
     */
    @PostMapping("/order")
    public ResultView order(OrderList orderList) {
        String managerId= StpUserUtil.getLoginIdAsString();
        SysManager sysManager=this.iSysManagerService.getById(managerId);
        Shop shop=this.iShopService.getById(orderList.getShopId());
        orderList.setCtime(new Date());
        orderList.setManagerId(managerId);
        orderList.setManagerName(sysManager.getMName());
        orderList.setPaytime(new Date());
        orderList.setStatus(2);
        orderList.setShopName(shop.getShopName());
        orderList.setPrice(shop.getShopPrice());
        orderList.setOrderId(IdentityUtil.identityId("OD"));
        boolean isOk=this.iOrderListService.save(orderList);
        if(isOk){
            return ResultView.ok();
        }else{
            return ResultView.error("下单支付失败");
        }
    }

}
